home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
tlfit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
165 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* tlfit -
* Fit a triangle list to a -1,1 -1,1 space.
*
* Paul Haeberli - 1990
*/
#include "math.h"
#include "stdio.h"
#include "vect.h"
#include "trilist.h"
main(argc,argv)
int argc;
char **argv;
{
int zonly;
if(argc<3) {
fprintf(stderr,"tlfit: in.tl out.tl [-z]\n");
exit(1);
}
if(argc>3)
zonly = 1;
else
zonly = 0;
tlfit(argv[1],argv[2],-0.95,0.95,-0.95,0.95,-1.0,1.0,zonly);
exit(0);
}
tlfit(inname,outname,xmin,xmax,ymin,ymax,zmin,zmax,zonly)
char *inname, *outname;
float xmin,xmax,ymin,ymax,zmin,zmax;
int zonly;
{
float delx, dely, delz;
float odelx, odely;
float tdelx, tdely;
float oxmin, oxmax;
float oymin, oymax;
float ozmin, ozmax;
float xmid, ymid;
float xavg, yavg;
float sc, zsc;
int i, ntri, mode;
trilisttri tri;
short magic;
FILE *outf;
delx = xmax-xmin;
dely = ymax-ymin;
delz = zmax-zmin;
oxmin = oymin = ozmin = 1000.0;
oxmax = oymax = ozmax = -1000.0;
ntri = tlopen(inname);
for(i=0; i<ntri; i++) {
tlread(&tri);
if(oxmin>tri.x0)
oxmin=tri.x0;
if(oxmax<tri.x0)
oxmax=tri.x0;
if(oymin>tri.y0)
oymin=tri.y0;
if(oymax<tri.y0)
oymax=tri.y0;
if(ozmin>tri.z0)
ozmin=tri.z0;
if(ozmax<tri.z0)
ozmax=tri.z0;
if(oxmin>tri.x1)
oxmin=tri.x1;
if(oxmax<tri.x1)
oxmax=tri.x1;
if(oymin>tri.y1)
oymin=tri.y1;
if(oymax<tri.y1)
oymax=tri.y1;
if(ozmin>tri.z1)
ozmin=tri.z1;
if(ozmax<tri.z1)
ozmax=tri.z1;
if(oxmin>tri.x2)
oxmin=tri.x2;
if(oxmax<tri.x2)
oxmax=tri.x2;
if(oymin>tri.y2)
oymin=tri.y2;
if(oymax<tri.y2)
oymax=tri.y2;
if(ozmin>tri.z2)
ozmin=tri.z2;
if(ozmax<tri.z2)
ozmax=tri.z2;
}
tlclose();
tdelx = odelx = oxmax-oxmin;
tdely = odely = oymax-oymin;
tdelx /= delx;
tdely /= dely;
if(tdelx>tdely)
mode = 1;
else
mode = 2;
switch(mode) {
case 1:
sc = delx/odelx;
break;
case 2:
sc = dely/odely;
break;
}
zsc = delz/(ozmax-ozmin);
xmid = (oxmin+oxmax)/2.0;
ymid = (oymin+oymax)/2.0;
xavg = (xmin+xmax)/2.0;
yavg = (ymin+ymax)/2.0;
ntri = tlopen(inname);
outf = fopen(outname,"w");
magic = TLMAGIC;
fwrite(&magic,sizeof(short),1,outf);
for(i=0; i<ntri; i++) {
tlread(&tri);
if(zonly) {
tri.z0 = zmin+zsc*(tri.z0-ozmin);
tri.z1 = zmin+zsc*(tri.z1-ozmin);
tri.z2 = zmin+zsc*(tri.z2-ozmin);
} else {
tri.x0 = xavg+(sc*(tri.x0-xmid));
tri.y0 = yavg+(sc*(tri.y0-ymid));
tri.z0 = zmin+zsc*(tri.z0-ozmin);
tri.x1 = xavg+(sc*(tri.x1-xmid));
tri.y1 = yavg+(sc*(tri.y1-ymid));
tri.z1 = zmin+zsc*(tri.z1-ozmin);
tri.x2 = xavg+(sc*(tri.x2-xmid));
tri.y2 = yavg+(sc*(tri.y2-ymid));
tri.z2 = zmin+zsc*(tri.z2-ozmin);
}
fwrite(&tri,sizeof(trilisttri),1,outf);
}
tlclose();
fclose(outf);
}